package cn.iocoder.yudao.module.reading.dal.mysql.assignment;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.reading.dal.dataobject.assignment.AssignmentClassDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 作业班级关联 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface AssignmentClassMapper extends BaseMapperX<AssignmentClassDO> {

    /**
     * 根据作业ID查询关联的班级ID列表
     */
    default List<Long> selectClassIdsByAssignmentId(Long assignmentId) {
        return selectList(new LambdaQueryWrapperX<AssignmentClassDO>()
                .eq(AssignmentClassDO::getAssignmentId, assignmentId))
                .stream()
                .map(AssignmentClassDO::getClassId)
                .collect(java.util.stream.Collectors.toList());
    }

    /**
     * 根据班级ID查询关联的作业ID列表
     */
    default List<Long> selectAssignmentIdsByClassId(Long classId) {
        return selectList(new LambdaQueryWrapperX<AssignmentClassDO>()
                .eq(AssignmentClassDO::getClassId, classId))
                .stream()
                .map(AssignmentClassDO::getAssignmentId)
                .collect(java.util.stream.Collectors.toList());
    }

    /**
     * 根据作业ID删除关联记录
     */
    default int deleteByAssignmentId(Long assignmentId) {
        return delete(AssignmentClassDO::getAssignmentId, assignmentId);
    }

    /**
     * 批量插入作业班级关联记录
     */
    default void insertBatch(List<AssignmentClassDO> assignmentClasses) {
        if (assignmentClasses != null && !assignmentClasses.isEmpty()) {
            for (AssignmentClassDO assignmentClass : assignmentClasses) {
                insert(assignmentClass);
            }
        }
    }

}
